package com.yeyks.commonReference.service.vip.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeyks.common.base.Arguments;
import com.yeyks.commonReference.service.vip.MiniVipCommissionOverviewService;
import com.yeyks.vip.dal.domain.MiniVipCommissionOverview;
import com.yeyks.vip.dal.dao.MiniVipCommissionOverviewMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;


/**
 * <p>
 * 精选小vip订单分佣总览表 服务实现类
 * </p>
 *
 * @author shuai
 * @since 2019-09-18
 */
@Service
public class MiniVipCommissionOverviewServiceImpl extends ServiceImpl<MiniVipCommissionOverviewMapper, MiniVipCommissionOverview> implements MiniVipCommissionOverviewService {

    /**
     * 通过分佣账户id获取小vip分佣账户
     *
     * @param accountId
     * @return
     */
    @Override
    public MiniVipCommissionOverview selectByAccountId(Integer accountId) {
        Arguments.intIsNull(accountId, "分佣账户id不能为空");
        MiniVipCommissionOverview overview = baseMapper.selectOne(new QueryWrapper<MiniVipCommissionOverview>().eq(MiniVipCommissionOverview.ACCOUNT_ID, accountId));
        if (null == overview) {
            return getMiniVipCommissionOverview(accountId);
        }
        return overview;
    }

    private MiniVipCommissionOverview getMiniVipCommissionOverview(Integer accountId) {
        MiniVipCommissionOverview overview = new MiniVipCommissionOverview();
        overview.setAccountId(accountId);
        overview.setTotalInAmount(0);
        overview.setTotalOutAmount(0);
        overview.setRemainAmount(0);
        Date date = new Date();
        overview.setCreateTime(date);
        overview.setUpdateTime(date);
        baseMapper.insert(overview);
        return overview;

    }
}
